import {
  avatarUploadApi,
  getAccessTokenApi,
  identifierAvailableApi,
  oauthTokenApi,
  sendCodeApi,
  signoutApi,
  updateBasicInfoApi,
  updateUserInfoApi,
  userInfoApi,
} from '../api/loginApi';

//获取应用级保护的access_token
export const getAccessTokenFun = (data: any = {}) => {
  return new Promise((reslve: any, reject: any) => {
    getAccessTokenApi(data)
      .then((res: any) => {
        reslve(res.access_token);
      })
      .catch((e: any) => {
        reject(e);
      });
  });
};
//判断账号是否可用(是否注册)
export const identifierAvailableFun = async (data: any) => {
  return new Promise((reslve: any, reject: any) => {
    identifierAvailableApi(data)
      .then((res: any) => {
        reslve(res);
      })
      .catch((e: any) => {
        console.log(e, 'e');
        reject(e);
      });
  });
};

// 获取验证码
export const sendCodeFun = async (data: any = {}) => {
  return new Promise((reslve: any, reject: any) => {
    sendCodeApi(data)
      .then((res: any) => {
        reslve(res);
      })
      .catch((e: any) => {
        reject(e);
      });
  });
};

//手机验证码登录
export const oauthTokenFun = async (data: any = {}) => {
  return new Promise((reslve: any, reject: any) => {
    oauthTokenApi(data)
      .then((res: any) => {
        reslve(res);
      })
      .catch((e: any) => {
        reject(e);
      });
  });
};

//基本信息查询
export const userInfoFun = async (data: any = {}) => {
  return new Promise((reslve: any, reject: any) => {
    userInfoApi(data)
      .then((res: any) => {
        console.log(res, '===基本信息查询');
        reslve(res);
      })
      .catch((e: any) => {
        reject(e);
      });
  });
};
//更新基本信息
export const updateBasicInfoFun = async (data: any = {}) => {
  return new Promise((reslve: any, reject: any) => {
    updateBasicInfoApi(data)
      .then((res: any) => {
        reslve(res);
      })
      .catch((e: any) => {
        reject(e);
      });
  });
};
//更新用户全量信息
export const updateUserInfoFun = async (data: any = {}) => {
  return new Promise((reslve: any, reject: any) => {
    updateUserInfoApi(data)
      .then((res: any) => {
        reslve(res);
      })
      .catch((e: any) => {
        reject(e);
      });
  });
};

//用户中心头像上传接口
export const avatarUploadFun = async (data: any = {}) => {
  return new Promise((reslve: any, reject: any) => {
    avatarUploadApi(data)
      .then((res: any) => {
        reslve(res);
      })
      .catch((e: any) => {
        reject(e);
      });
  });
};

//退出登录
export const signoutFun = async (data: any = {}) => {
  return new Promise((reslve: any, reject: any) => {
    signoutApi(data)
      .then((res: any) => {
        reslve(res);
      })
      .catch((e: any) => {
        reject(e);
      });
  });
};
